﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DelonixRegiaHMSys.Core.Services;
using DelonixRegiaHMSys.Infrastructure.Data;
using DelonixRegiaHMSys.UI.Models;

namespace DelonixRegiaHMSys.UI.WebForms
{
    public partial class SystemAccountManagement : System.Web.UI.Page
    {
        string userIDs;
        protected void Page_Load(object sender, EventArgs e)
        {
            userIDs = Request.QueryString["UserID"];
            if (!IsPostBack)
            {
                BindGridView();
            }
        }

        private void BindGridView()
        {
            var saservice = new saServices(new EfSystemAccountQuery());
            GridViewSA.DataSource = saservice.GetAll().ToList();
            GridViewSA.DataBind();
        }

        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            string userID = (((LinkButton)sender).CommandArgument);
            var saservice = new saServices(new EfSystemAccountQuery());
            saservice.DeleteUser(userID);
            BindGridView();
        }

        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            string[] arg = new string[5];
            arg = ((LinkButton)sender).CommandArgument.ToString().Split(';');
            string userID = arg[0];
            string password = arg[1];
            string accessLevel = arg[2];
            string staffID = arg[3];
            string userStatus = arg[4];

            string querystring = "UserID=" + userIDs + "&User=" + userID + "&Password=" + password + "&AccessLevel=" + accessLevel + "&StaffID=" + staffID + "&UserStatus=" + userStatus;
            Server.Transfer("~/WebForms/SystemAccountModule/UpdateSystemAccount.aspx?" + querystring);
        }

        protected void lbtnASA_Click(object sender, EventArgs e)
        {
            Server.Transfer("~/WebForms/SystemAccountModule/AddSystemAccount.aspx?UserID=" + userIDs);
        }

        protected void MainpageButton_Click(object sender, EventArgs e)
        {

            Server.Transfer("~/WebForms/SystemAccountModule.MainPage.aspx?UserID=" + userIDs);
       
        }
    }
}